﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Petaframe.DataAccess.UnitTest.helpers;
using SharpTestsEx;
using Oracle.DataAccess.Client;
using System.Data.SqlClient;

namespace Petaframe.DataAccess.UnitTest
{
   
    [TestClass()]
    public class ClassDecomposerTestOracle : ClassPropertyAndInfoTestBase
    {
        /// <summary>
        ///A test for ClassDecomposer Constructor
        ///</summary>
        [TestMethod()]
        public void ClassDecomposerConstructorTest()
        {
            ClassDecomposer target = new ClassDecomposer();
            Assert.IsNotNull(target);
        }

        /// <summary>
        ///A test for ForEntity
        ///</summary>
        public void ForEntityTestHelper<T>()
        {
            ClassDecomposer target = new ClassDecomposer();
            T obj = Activator.CreateInstance<T>();

            TableInfo actual;
            actual = target.ForEntity<T>(obj, new OracleParameterBuilder(), new OracleEscapeSqlIdentifier(),_oracProvider);
            actual.Should().Be.EqualTo(this.expectedTableInfoOracle);
        }

        [TestMethod()]
        public void ForEntityTest()
        {
            ForEntityTestHelper<Category>();
        }

        /// <summary>
        ///A test for ForObject
        ///</summary>
        [TestMethod()]
        public void ForObjectTest()
        {
            ClassDecomposer target = new ClassDecomposer();
            object obj = new Category();

            TableInfo actual;
            actual = target.ForObject(obj, new OracleParameterBuilder(), new OracleEscapeSqlIdentifier(), _oracProvider);
            Assert.AreEqual(expectedTableInfoOracle, actual);

        }

        /// <summary>
        ///A test for ForType
        ///</summary>
        [TestMethod()]
        public void ForTypeTest()
        {
            ClassDecomposer target = new ClassDecomposer();
            Type tip = new Category().GetType();

            TableInfo actual;
            actual = target.ForType(tip, new OracleParameterBuilder(), new OracleEscapeSqlIdentifier(), _oracProvider);
            Assert.AreEqual(expectedTableInfoOracle, actual);

        }

        [TestMethod]
        public void HasPrimaryKeyShouldBeTrue()
        {
            ClassDecomposer target = new ClassDecomposer();
            TableInfo actual = target.ForEntity(testArgument, new OracleParameterBuilder(), new OracleEscapeSqlIdentifier(), _oracProvider);
            actual.HasPrimaryKey.Should().Be.True();
        }

        [TestMethod]
        public void TableNameShouldBeInQuotasAndUpperCase()
        {
            ClassDecomposer target = new ClassDecomposer();
            TableInfo actual = target.ForEntity(testArgument, new OracleParameterBuilder(), new OracleEscapeSqlIdentifier(), _oracProvider);
            actual.TableName.Should().Be.EqualTo("\"CATEGORIES\"");
        }
       

        [TestMethod]
        public void PropertiesCountShouldBeThree()
        {
            ClassDecomposer target = new ClassDecomposer();
            TableInfo actual = target.ForEntity(testArgument, new OracleParameterBuilder(), new OracleEscapeSqlIdentifier(), _oracProvider);
            actual.Properties.Count.Should().Be.EqualTo(3);
        }

        [TestMethod]
        public void FirstPropertyShouldBeID()
        {
            ClassDecomposer target = new ClassDecomposer();
            TableInfo actual = target.ForEntity(testArgument, new OracleParameterBuilder(), new OracleEscapeSqlIdentifier(), _oracProvider);
            actual.Properties[0].PropertyName.Should().Be.EqualTo("CategoryID");
        }

        [TestMethod]
        public void FirstPropertyShouldBePrimaryKey()
        {
            ClassDecomposer target = new ClassDecomposer();
            TableInfo actual = target.ForEntity(testArgument, new OracleParameterBuilder(), new OracleEscapeSqlIdentifier(), _oracProvider);
            actual.Properties[0].PrimaryKey.Should().Be.True();
        }

        [TestMethod]
        public void NullTableNameAttributeThrows()
        {
            ClassDecomposer target = new ClassDecomposer();
            target.Executing(z => z.ForEntity(new CategoryWithoutTableNameAttribute(), new OracleParameterBuilder(), new OracleEscapeSqlIdentifier(), _oracProvider)).Throws();

        }

    }
}
